﻿


using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using Abp;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.AutoMapper;
using Abp.Configuration;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.Linq.Extensions;
using KDS.Mes.Mes.Atlas.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;
#region 代码生成器相关信息_ABP Code Generator Info
//你好，我是ABP代码生成器的作者,欢迎您使用该工具，目前接受付费定制该工具，有需要的可以联系我
//我的邮箱:werltm@hotmail.com
// 官方网站:"http://www.yoyocms.com"
// 交流QQ群：104390185  
//微信公众号：角落的白板报
// 演示地址:"vue版本：http://vue.yoyocms.com angularJs版本:ng1.yoyocms.com"
//博客地址：http://www.cnblogs.com/wer-ltm/
//代码生成器帮助文档：http://www.cnblogs.com/wer-ltm/p/5777190.html
// <Author-作者>梁桐铭 ,微软MVP</Author-作者>
// Copyright © YoYoCms@China.2017-10-24T20:27:17. All Rights Reserved.
//<生成时间>2017-10-24T20:27:17</生成时间>
#endregion
namespace KDS.Mes.Mes.Atlas
{
    /// <summary>
    /// Atlas数据表的导出EXCEL功能的实现
    /// </summary>
    public class AtlasListExcelExporter : EpPlusExcelExporterBase, IAtlasListExcelExporter
    {

        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public AtlasListExcelExporter(ITimeZoneConverter timeZoneConverter, IAbpSession abpSession)
        {
            _timeZoneConverter = timeZoneConverter;
            _abpSession = abpSession;
        }



        /// <summary>
        /// 导出Atlas数据表到EXCEL文件
        /// <param name="atlasListDtos">导出信息的DTO</param>
        /// </summary>
        public FileDto ExportAtlasToFile(List<AtlasListDto> atlasListDtos)
        {


            var file = CreateExcelPackage("atlasList.xlsx", excelPackage =>
            {

                var sheet = excelPackage.Workbook.Worksheets.Add(L("Atlas"));
                sheet.OutLineApplyStyle = true;

                AddHeader(
                    sheet,
                      L("LINE"),
 L("STATION_NO"),
 L("SEAT_ID"),
 L("LENGTHS"),
 L("MID"),
 L("REVISION"),
 L("ACK_FLAG"),
 L("CELL_ID"),
 L("CHANNEL_ID"),
 L("CONTROLLER_NAME"),
 L("JOB_ID"),
 L("PARAMETER_SET_ID"),
 L("BATCH_SIZE"),
 L("BATCH_COUNTER"),
 L("TIGHTENING_STATUS"),
 L("TORQUE_STATUS"),
 L("ANGLE_STATUS"),
 L("TORQUE_MIN_LIMIT"),
 L("TORQUE_MAX_LIMIT"),
 L("TORQUE_FINAL_TARGET"),
 L("TORQUE"),
 L("ANGLE_MIN"),
 L("ANGLE_MAX"),
 L("FINALl_ANGLE_TARGET"),
 L("ANGLE"),
 L("TIME_STAMP"),
 L("TIME_OF_LAST_CHANGE"),
 L("BATCH_STATUS"),
 L("TIGHTENING_ID"),
 L("CREAT_TIME")
                    );
                AddObjects(sheet, 2, atlasListDtos,

             _ => _.LINE,

             _ => _.STATION_NO,

             _ => _.SEAT_ID,

             _ => _.LENGTHS,

             _ => _.MID,

             _ => _.REVISION,

             _ => _.ACK_FLAG,

             _ => _.CELL_ID,

             _ => _.CHANNEL_ID,

             _ => _.CONTROLLER_NAME,

             _ => _.JOB_ID,

             _ => _.PARAMETER_SET_ID,

             _ => _.BATCH_SIZE,

             _ => _.BATCH_COUNTER,

             _ => _.TIGHTENING_STATUS,

             _ => _.TORQUE_STATUS,

             _ => _.ANGLE_STATUS,

             _ => _.TORQUE_MIN_LIMIT,

             _ => _.TORQUE_MAX_LIMIT,

             _ => _.TORQUE_FINAL_TARGET,

             _ => _.TORQUE,

             _ => _.ANGLE_MIN,

             _ => _.ANGLE_MAX,

             _ => _.FINALl_ANGLE_TARGET,

             _ => _.ANGLE,

             _ => _.TIME_STAMP,

             _ => _.TIME_OF_LAST_CHANGE,

             _ => _.BATCH_STATUS,

             _ => _.TIGHTENING_ID,

        _ => _timeZoneConverter.Convert(_.CREAT_TIME, _abpSession.TenantId, _abpSession.GetUserId())
       );
                //写个时间转换的吧
                //var creationTimeColumn = sheet.Column(10);
                //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

                for (var i = 1; i <= 30; i++)
                {
                    sheet.Column(i).AutoFit();
                }

            });
            return file;

        }







    }
}
